﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：PriceAdjustPlanList.cs
    // 文件功能描述：采购产品管理：价格调整计划列表
    // 创建标识：吕海乐2009-03-24
    //
    // 修改标识：Zeus2
    // 修改描述：2009-3-27
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class PriceAdjustPlanList : BasePage
    {
        private IBLL_ProcurementBasic ibp = Factory.BLL_ProcurementBasic();

        public PriceAdjustPlanList()
        {
            this.ModuleNo = Module.调价计划列表.ToString();
            this.PageOperateType = OperateType.调价计划列表.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                BindData();
            }
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {

            BindData();
        }

        protected void BindData()
        {
            Model.Query.AdjustPricePlan where = new HZ.DrugTrade.Model.Query.AdjustPricePlan();

            //where.AdjustPriceReason = txtAdjustPriceReason.Text;
            where.ExecuteStartTimeFrom = new HZ.Common.ConvertHelper(txtExecuteStartTime.Text.Trim()).ToDateTime;
            where.ExecuteStartTimeTo = new HZ.Common.ConvertHelper(txtExecuteEndTime.Text.Trim()).ToDateTime;
            where.PlanTimeFrom = new HZ.Common.ConvertHelper(txtPlanTimeFrom.Text.Trim()).ToDateTime;
            where.PlanTimeTo = new HZ.Common.ConvertHelper(txtPlanTimeTo.Text.Trim()).ToDateTime;
            where.GoodsName = txtGoodsName.Text.Trim();
            where.PlanPerson = txtPlanPerson.Text.Trim();
            where.SortFields = "PlanTime DESC";
            int totalrecord;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;

            IList<Model.View.AdjustPricePlan> list = ibp.GetAdjustPricePlanByWhere(where, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);

            AspNetPager1.RecordCount = totalrecord;
            GridView1.DataSource = list;
            GridView1.DataBind();
        }

        /// <summary>
        /// 多条件查询价格调整计划
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                AspNetPager1.CurrentPageIndex = 1;
                BindData();
            }
            catch (Exception ex)
            {
                PageError(ex.Message, "");
            }
        }



        //protected void linkProcureCatalogID_Click(object sender, EventArgs e)
        //{
        //    LinkButton lb = sender as LinkButton;
        //    string proid = lb.CommandArgument;
        //    int inttmp;
        //    Model.View.ProcureCatalog pc = ibp.GetProcureCatalogByWhere(new HZ.DrugTrade.Model.Query.ProcureCatalog() { ProcureCatalogID = proid, SortFields = "ProcureCatalogID" }, 1, 0, out inttmp)[0];

        //    //ltlProcureCatalog.Text = GetFormatStringFromProcureCatalog(pc);

        //    //ModalPopupExtender.Show();
        //}

        //protected void btnModify_Click(object sender, EventArgs e)
        //{
        //    //int r = ibp.UpdateAdjustPricePlan(new AdjustPricePlan()
        //    //  {
        //    //      PricePlanSerialID = ViewState["PricePlanSerialID"].ToString(),
        //    //      AdjustPrice = decimal.Parse(txtNewPrice.Text),
        //    //      AdjustPriceReason = txtReason.Text,
        //    //      ExecuteState = 0,
        //    //      ExecuteWay = ddlType.SelectedIndex,
        //    //      PlanPerson = "Zeus2",
        //    //      PlanTime = DateTime.Now,
        //    //      ExecuteStartTime = DateTime.Parse(txtExecuteTime.Text),
        //    //      ProcureCatalogID = ViewState["ProcureCatalogID"].ToString()
        //    //  });
        //    //if (r == 0)
        //    //{
        //    //    HZ.Web.MessageBox.Show("更新失败？？");
        //    //}
        //    //BindData();
        //    //ModifyPopUp.Hide();
        //}

        //private string GetFormatStringFromProcureCatalog(Model.View.ProcureCatalog ProcureCatalog)
        //{
        //    System.Text.StringBuilder formatstring = new System.Text.StringBuilder(512);
        //    formatstring.AppendFormat("<B>通用名:</B>{0} ", ProcureCatalog.ProductName);
        //    formatstring.AppendFormat("<B>剂型:</B>{0} ", ProcureCatalog.MedicineModelName);
        //    formatstring.AppendFormat("<B>规格:</B>{0} ", ProcureCatalog.Outlookc);
        //    formatstring.AppendFormat("<B>单位:</B>{0} ", ProcureCatalog.Unit);
        //    formatstring.AppendFormat("<B>转换系数:</B>{0} ", ProcureCatalog.Factor);
        //    formatstring.AppendFormat("<B>生产企业:</B>{0} ", ProcureCatalog.CompanyName_SC);
        //    formatstring.AppendFormat("<B>分类:</B>{0} ", ProcureCatalog.SortName);
        //    return formatstring.ToString();
        //}

        /// <summary>
        /// 执行删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Del"))
            {
                string ppsId = e.CommandArgument.ToString();

                int result = ibp.DeleteAdjustPricePlanByID(ppsId);
                if (result == 0)
                {
                    PageError("删除失败！", this.ReturnUrl);

                }
                //重写绑定
                BindData();
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            Model.Query.AdjustPricePlan applan = new HZ.DrugTrade.Model.Query.AdjustPricePlan();

            //where.AdjustPriceReason = txtAdjustPriceReason.Text;
            applan.ExecuteStartTimeFrom = new HZ.Common.ConvertHelper(txtExecuteStartTime.Text.Trim()).ToDateTime;
            applan.ExecuteStartTimeTo = new HZ.Common.ConvertHelper(txtExecuteEndTime.Text.Trim()).ToDateTime;
            applan.PlanTimeFrom = new HZ.Common.ConvertHelper(txtPlanTimeFrom.Text.Trim()).ToDateTime;
            applan.PlanTimeTo = new HZ.Common.ConvertHelper(txtPlanTimeTo.Text.Trim()).ToDateTime;
            applan.GoodsName = txtGoodsName.Text.Trim();
            applan.PlanPerson = txtPlanPerson.Text.Trim();
            applan.SortFields = "PlanTime DESC";
            int totalcount = 0;
            //IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
            //DataTable dt = ipb.GetAdjustPricePlanDTByWhere(applan, 1, 0, out totalcount);
            ////HZ.Data.ModelConvert.GetDataTableFromModel(procureCatalogList);
            //HZ.Excel.ExcelHelper.ExportDataForWeb(dt,this.GridView1);
            string where = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition<HZ.DrugTrade.Model.Query.AdjustPricePlan>(applan, true);
            string sql = string.Format(@"SELECT PricePlanSerialID 调价计划流水号,GoodsName 产品名称,Outlookc 规格型号,Unit 单位,
                                        companyname_sc 生产企业,OriginalPrice 原价,AdjustPrice 新价,ExecuteStartTime 执行时间,AdjustPriceReason 调价原因,
                                        PlanPerson 制定人,case ExecuteState when 1 then '已执行' else '未执行' end as 执行状态,
                                        case ExecuteWay when 0 then '立即执行' else '定时执行' end as 执行方式, PlanTime 创建时间 FROM View_AdjustPricePlan WHERE 1=1 {0}", where);
            HZ.DrugTrade.BLL.ExcelHelper.ExportByWeb(HZ.Data.DbHelperFactory.Create().ExecuteTable(sql), "", "调价计划.xls");
        }
     
    }
}
